package DeportManage;

import java.util.*;

public class ParcelList{
	HashMap<String, Parcel> parcel_map;
	
	public ParcelList(){
		parcel_map = new HashMap<String, Parcel>();
	}
	/**
	 * Method to get parcel
	 * @return a hashMap of parcel
	 */
	public HashMap<String, Parcel> getParcel(){
		return parcel_map;
	}
	/**
	 * Method to add parcel in the parcelList
	 * @throws DuplicateException 
	 */
	public void addParcel(Parcel parcel) throws DuplicateException{
		String id = parcel.getID();
		if(isExistParcel(id) == false){
			parcel_map.put(id, parcel);
		}	
		else
			throw new DuplicateException(id);
	}
	/**
	 * Method to ensure whether there is same parcel
	 * @return boolean true or false
	 */
	public boolean isExistParcel(String id){	
			if(parcel_map.containsKey(id))
				return true;
			else
				return false;
	}
	/**
	 * Method to search parcel parcel by parcel ID
	 * @return the parcel which be found
	 * @throws NotFoundParcelIDException 
	 */
	public Parcel searchParcelByParcelID(String id) throws NotFoundParcelIDException{	
			if(parcel_map.containsKey(id))
				return parcel_map.get(id);
			else
				throw new NotFoundParcelIDException(id);
	}
	/**
	 * Method to remove parcel by parcel ID
	 * @return a boolean to check whether the parcel has been removed
	 * @throws NotFoundParcelIDException 
	 */
	public void removeParcelByParcelID(String id) throws NotFoundParcelIDException{
		if(isExistParcel(id) == true)
			parcel_map.remove(id);
		else
			throw new NotFoundParcelIDException(id);
	}
}